<?php

class Core_Data_SQL_DataTypes {

    const INT8 = 1;
    const INT16 = 2;
    const INT24 = 3;
    const INT32 = 4;
    const INT64 = 5;
    const TEXT = 6;

    const UNKNOWN = 100;

    public static function getQueryText ( $constDataType, $constServerType ) {

        switch ( $constServerType ) {

            case Core_Data_SQL_ServerTypes::MYSQL:

                switch ( $constDataType ) {

                    case self::INT8:
                        return "TINYINT";
                    case self::INT16:
                        return "SMALLINT";
                    case self::INT24:
                        return "MEDIUMINT";
                    case self::INT32:
                        return "INT";
                    case self::INT64:
                        return "BIGINT";
                    case self::TEXT:
                        return "TEXT";

                }


        }

    }

    public static function getFromResultText ( $strResultText, $constServerType, &$intLength ) {

        switch ( $constServerType ) {

            case Core_Data_SQL_ServerTypes::MYSQL:

                $strPattern = "/([a-z]+)(\(([\d]+)\))?/";
                preg_match( $strPattern, $strResultText, $arrMatches );

                $intLength = ( isset( $arrMatches[3] ) ) ? $arrMatches[3] : null;

                switch ( $arrMatches[1] ) {

                    case "tinyint":
                        return self::INT8;
                    case "smallint":
                        return self::INT16;
                    case "mediumint":
                        return self::INT24;
                    case "int":
                        return self::INT32;
                    case "bigint":
                        return self::INT64;
                    case "text":
                        return self::TEXT;
                    default:
                        return self::UNKNOWN;

                }


        }

    }

}

?>
